<?php

namespace app\admin\validate;

use think\Validate;

class Shop extends Validate
{

    protected $scene = [
        'EditInfo' => ['shopname','shopphone','address','ahead_days','mini_number','notice_text','shopmanager','time_range','state','imagesurl','kefu_image','remark'],
    ];

    protected $rule =   [
        'time_range'  => 'require|array|checkRange',
        'shopname'  => 'require',
        'remark'  => 'require',
        'shopphone'  => 'require|mobile',
        'address'  => 'require',
        'ahead_days'  => 'require|number',
        'mini_number'  => 'require|number',
        'notice_text'  => 'require',
        'shopmanager'  => 'require',
        'imagesurl'  => 'require',
        'kefu_image'  => 'require',
        'persons'  => 'require|number',
        'limit_number'  => 'require|number',
    ];

    protected $message  =   [
        'time_range.require' => '营业时间范围必须',
        'time_range.array' => '营业时间范围上传参数格式错误',
        'shopname.require' => '店铺名称必须',
        'remark.require' => '店铺简介必须',
        'shopphone.require' => '联系电话必须',
        'shopphone.mobile' => '联系电话格式错误',
        'address.require' => '店铺地址必须',
        'notice_text.require' => '店铺公告必须',
        'shopmanager.require' => '店长名字必须',
        'imagesurl.require' => '店长封面图必须',
        'kefu_image.require' => '客服联系二维码必须',
        'state.number'   => '状态必须是数字',
        'ahead_days.require' => '提前天数必须',
        'ahead_days.number'   => '提前天数错误',
        'mini_number.require' => '最低起送份数必须',
        'mini_number.number'   => '最低起送份数错误',
        'persons.require' => '人数限制必须',
        'persons.number'   => '人数必须是数字',
        'limit_number.require' => '时间段下单数限制必须',
        'limit_number.number'   => '时间段下单数必须是数字',
    ];

    protected function checkRange($ranges)
    {
        foreach($ranges as $value){
            $time_range = explode(" - ",$value);
//            var_dump($time_range);
            if($time_range[0] > $time_range[1]){
                return '打烊时间不能大于营业时间';
            }
            return true;
        }
    }
}
